package com.fs.base.vo;

import com.fs.base.exception.enums.ExcEnum;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author Administrator
 */
@Data
@AllArgsConstructor
public class JsonResponse {
	/*
	 * 消息码
	 */
	private Integer code;
	/*
	 * 信息内容
	 */
	private String msg;
	/*
	 * 成功或失败
	 */
	private Boolean flag ;
	
	/*
	 * 附加数据
	 */
	private Object data;
	
	public JsonResponse (Boolean flag,String msg){
		this.flag = flag;
		this.msg = msg;
	}
	public JsonResponse (Boolean flag,Object data){
		this.flag = flag;
		this.data = data;
	}
	public JsonResponse (Boolean flag,Integer code,String msg){
		this.flag = flag;
		this.code = code;
		this.msg = msg;
	}
	
	public static JsonResponse success(){
		return new JsonResponse(true, "成功");
	}

	public static JsonResponse success(String msg){
		return new JsonResponse(true, msg);
	}
	
	public static JsonResponse success(Object data){
		return new JsonResponse(true, data);
	}
	
	public static JsonResponse success(Integer code,String msg){
		return new JsonResponse(true, code,msg);
	}
	
	
	public static JsonResponse error(){
		return new JsonResponse(false, "失败");
	}
	
	public static JsonResponse error(String msg){
		return new JsonResponse(false, msg);
	}
	
	public static JsonResponse error(Object data){
		return new JsonResponse(false, data);
	}

	public static JsonResponse error(Integer code,String msg){
		return new JsonResponse(false, code,msg);
	}
	
	public static JsonResponse error(ExcEnum exc){
		return new JsonResponse(false, exc.getCode(),exc.getMsg());
	}
}
